var p = 0;
//打印控件调用
var LODOP; //声明为全局变量

//进度条
function progress_bar(val){
    //LODOP=getLodop();
    //LODOP.FORMAT("VOICE:0;100","正在打印请稍后！");
    //屏幕宽度
    var width=$("#progress_bar").clientWidth;
    p+=val;
    if(p%10==1){
        LODOP=getLodop();
        LODOP.FORMAT("VOICE:0;100","d:/bingandayin.wav");
    }
    $("#bar_dy").css("width",p+"%");
    if(p<90){
        var timer=setTimeout("progress_bar("+val+")",500);
        //$("#bar_div_dy").css("margin-left",p/150*width);
    }else{
        $("#bar_font").html("即将打印完成，请稍后！");
        $("#bar_div_dy").css("margin-left",0.3*width);
    }
}

//进度条
function progress_bar_dq(val, pl){
    //屏幕宽度
    var width=$("#progress_bar").clientWidth;
    pl+=val;
   
    $("#bar_dy").css("width",pl+"%");
    
    if(pl<90){
        var timer=setTimeout("progress_bar_dq("+val+","+pl+")",500);
        //$("#bar_div_dy").css("margin-left",pl/120*width);
    } else {
    	//删掉调取病案进度条
        $("#dy_alert").remove();
       /* $("#myModal").append("<div class='alert_warn_new modal' id='dy_alert'><div class='warn_div_dq'><font class='font12' id='warn'>请稍后，正在打印病案...</font></div></div>");
        $("#dy_alert").append("<div class='alert fade in bar_warn warn_dq' id='bar_close'><div  class='progress progress-striped active'><div class='bar' " +
        		"id='bar_dy' style='width: 1%;'></div></div></div>");
        p=0;
        progress_bar(2);*/
    }
    
    
}

//刻录进度条
function progress_dvd(val){
    //屏幕宽度
    var basepath=$("#basepath").val();
    var width=document.body.clientWidth;
    p+=val;
    if(p<=30){
        var timer=setTimeout("progress_dvd("+val+")",500);
        $("#bar_dvd").css("width",p+"%");
        $("#bar_dvd_div").css("margin-left",p/120*width);
    }else{
        $.ajax({
            cache: true,
            type:"POST",
            url:basepath+"/spmr/acquireProgress",
            dataType:"json",
            data:{},
            async: true,
            beforeSend: function(xhr){
                xhr.setRequestHeader(header, token);
            },
            success:function(data){
                var status=data.status;
                var rate=data.rate;//进度
                if(status=='inp'){
                    if(rate>0.40&&rate<0.90){
                        var timer=setTimeout("progress_dvd("+p+")",500);
                        $("#bar_dvd]").css("width",rate*100+"%");
                        $("#bar_dvd_div").css("margin-left",rate/1.2*width);
                    }else if(rate>0.90){
                        var timer=setTimeout("progress_dvd("+p+")",500);
                        $("#bar_dvd").css("width",progress*width+"%");
                        $("#bar_dvd_div").css("margin-left",0.4*width);
                    }else{
                        var timer=setTimeout("progress_dvd("+p+")",500);
                    }
                }else if(status=='don'){
                    close_war_dvd();
                }

            },
            error:function(){
                $(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div'><font class='font9' id='warn'>刻录失败，请联系客服！</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
                settime_warn($("#btn_warn"));
            }
        });


    }
}

//进度条（单位进度,份数,当前份数）
function progress_bar_(val,fs,num){
    //屏幕宽度
    var width=document.body.clientWidth;
    //进度条宽度
    p+=val;
    if(p%10==1){
        LODOP=getLodop();
        LODOP.FORMAT("VOICE:0;100","d:/bingandayin.wav");
    }

    if(p<90){
        //份数大于1，进度条显示
        if(fs>1){
            //进度条到达相应份数百分比时
            /* if(p<100/fs*num){
                $("div[class=bar]").css("width",p/fs+"%");
                var timer=setTimeout("progress_bar("+val+","+fs+","+num+")",500);
                $("#bar_font").html("正在打印第"+num+"份病例！");
                $("div[class=bar_div]").css("margin-left",p/(120*num)*width);
            }else{
                $("div[class=bar]").css("width",num/fs+"%");
                $("#bar_font").html("正在打印第"+num+"份病例！");
                $("div[class=bar_div]").css("margin-left",p/(120*num)*width);
            }			 */
            if(num>(p*fs/100)){
                $("#bar_dy").css("width",p+"%");
                $("#bar_font").html("正在打印第"+num+"份病例！");
                $("#bar_div_dy").css("margin-left",p/(120*num)*width);
                setTimeout("progress_bar("+val+","+fs+","+num+")",500);
            }else{
                $("#bar_font").html("正在打印第"+num+"份病例！");
                $("#bar_div_dy").css("margin-left",num/(fs*1.20)*width);
            }
        }else{
            $("#bar_dy").css("width",p/num+"%");
            setTimeout("progress_bar("+val+","+fs+","+num+")",500);
            $("#bar_div_dy").css("margin-left",p/120*width);
        }

    }else{//进度条达到90时，停止等待
        $("#bar_font").html("即将打印完成，请稍后！");
        $("#bar_div_dy").css("margin-left",0.4*width);
    }

}

//提示装订完成
function close_war(){
    $(".span_div").remove();
    $("#myModal").attr("class","modal_dy hide");
    $(document.body).append("<div class='alert fade in alert_warn_1'><div class='warn_div_1'><font class='font12' id='warn'>打印完毕，请取出装订！</font></div></div>");
    //settime_down($("#btn_warn"),10);

    setTimeout("window.location.reload()",4000);
    //选择刻录后显示，刻录进度条
    var dvdCheck=$("#dvdChoice").val();
    if(dvdCheck==1){
        $(document.body).append("<div class='alert fade in bar_warn' id='bar_dvd_close'><div  class='progress progress-striped active'><div class='bar' id='bar_dvd' style='width: 1%;'></div></div><div class='bar_div_dvd'><font id='bar_font' class='font9'> 正在刻录请稍后...</font></div></div>");
        progress_dvd(1);
    }else{
        //setTimeout("window.location.reload()",4000);
    }

}


//打印时显示“调出病历请稍后”
function settime_progress(val,progress) {


    if (progress <= 0) {
        val.remove();
        /*$("#send").attr("disabled", false);
        $("#card_read").attr('disabled',false);
        $("#confirm_").attr("disabled", false);*/
        //$(".btn_fs").attr("disabled",false);
        $("#myModal").append("<div class='alert_warn_new modal' id='dy_alert'><div class='warn_div_dq'><font class='font12' id='warn'>请稍后，正在打印病案...</font></div></div>");
        $("#dy_alert").append("<div class='alert fade in bar_warn warn_dq' id='bar_close'><div  class='progress progress-striped active'><div class='bar' id='bar_dy' style='width: 1%;'></div></div></div>");
        p=0;
        progress_bar(2);

        //warndown = 5;
    } else {
        progress--;
        //$("#warn_dy").html(progress);
        setTimeout(function() {
            settime_progress(val,progress);
        },1000);
    }

}


function close_reload(){
    setTimeout("window.location.reload()",100);
}

function close_confirm(){
    if(confirm("退出当前页面,回主页?")){
        setTimeout("window.location.reload()",100);
    }

}

//关闭刻录进度条
function close_war_dvd(){
    $("#bar_dvd_close").remove();
    $(document.body).append("<div class='alert fade in alert_warn_'><button type='button' id='btn_warn' onclick='close_warn()' class='close'>&times;</button><div class='warn_div_1'><font class='font9' id='warn'>刻录完成！</font></div>	<div class='warn_div_'><font class='font5' id='warn_'>5</font></div></div>");
    settime_warn($("#btn_warn"));
    //setTimeout("window.location.reload()",5000);
    $("#myModal").attr("class","modal modal_dy ");
    $("#dvdModal").attr("class","modal modal_dy hide");
    setTimeout("window.location.reload()",5000);
}

function test(){
    p=10;
    //屏幕宽度
    var width=document.body.clientWidth;

    $(document.body).append("<div class='alert fade in bar_warn' id='bar_close'><div  class='progress progress-striped active'><div class='bar' style='width: 2%;'></div></div><div class='bar_div'><font id='bar_font' class='font9'>  正在打印请稍后...</font></div></div>");
    progress_bar(1);
}


